/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package presenter;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import javax.media.Player;
import javax.media.Renderer;
import javax.media.control.FrameGrabbingControl;
import javax.swing.JComponent;
import javax.swing.JLayeredPane;
import javax.swing.JPanel;
import javax.swing.Timer;

/**
 *
 * @author Al
 */
public class TransparentFrame extends JPanel implements ActionListener{
    public static final long serialVersionUID=2;
    Timer t;
    Image background;
    Player pl;
    Renderer r;
    FrameGrabbingControl fgc;
    JPanel jp;
    JLayeredPane jlp;
    
    public TransparentFrame(JPanel jp) {
        super();
        setIgnoreRepaint(true);
        t=new Timer(40,this);
        t.start();
        this.jp=jp;
        setBackground(new Color(0,0,0,0));
        //fgc=(FrameGrabbingControl)pl.getControl("javax.media.control.FrameGrabbingControl");
        //setLocation(jf.getX(),jf.getY());
        //jf.setLocation(jf.getX()+jf.getWidth(),jf.getY());
    }
    
   /* public void updateBackground (){
        try {
        Robot rbt = new Robot( );
        Toolkit tk = Toolkit.getDefaultToolkit( );
        Dimension dim = tk.getScreenSize( );
        background = rbt.createScreenCapture(
        new Rectangle(jf.getX(),jf.getY(),jf.getWidth(),
                          jf.getHeight()));
        } catch (Exception ex) {
            ex.printStackTrace( );
        }
    }*/
    
    
    public void paintComponent(Graphics g) {
        super.paintComponent(g);
        
        BufferedImage bi=new BufferedImage(jp.getWidth(),jp.getHeight(),BufferedImage.TYPE_INT_RGB);
        Graphics gr=bi.getGraphics();
        jp.paintAll(gr);
        background=(Image) bi;
        //System.out.println("painting "+background);
        if(background==null)
           //System.out.println("crap");
       // else //System.out.println("go");
        //if(g==null) //System.out.println("weird");
        /*if(fgc==null);
            //System.out.println("fgc null");
        else {
            Buffer frame=fgc.grabFrame();

            // Convert frame to an buffered image so it can be processed and saved
           
            if(frame==null)
                //System.out.println("frame null");
            else{
                //System.out.println("not null");
                BufferToImage bti=new BufferToImage((VideoFormat)frame.getFormat());
                background=(Image) bti.createImage(frame);
*/
               // g.drawImage(background,0,0,getWidth(),getHeight(),this);
                g.drawString("hello", 100, 100);
            //}
        //}
    }

    public void actionPerformed(ActionEvent e) {
        //throw new UnsupportedOperationException("Not supported yet.");
        //paint(getGraphics());
        repaint();
    }
    
    
}
